<template>
  <div class="header-wrapper">
    <div class="header-box">
      <div class="search-wrapper flex-x-bet-y-center">
        <router-link to="/" class=" left flex-x-bet-y-center" style="text-decoration: none;">
          <img src="@/assets/img/logo.png" class="logo" alt="" />
          <span class="name">设备租赁</span>
        </router-link>
        <div class="center flex-x-bet-y-center flex-1">
          <div class="flex-y-center flex-1">
            <el-select v-model="searchType" :popper-append-to-body="false">
              <el-option
                v-for="(item, index) in searchTypeList"
                :key="item.value"
                :value="item.value"
                :label="item.label"
              ></el-option>
            </el-select>
            <input type="text" v-model="keywords" placeholder="请输入" class="search-input" />
          </div>
          <div class="search-btn flex-xy-center" @click="searchConfirm">
            <img src="@/assets/img/icon-search.png" class="icon-search" alt="" />
          </div>
        </div>
        <div class="right flex-y-center">
          <el-button type="primary" style="background-color: #3a71fb; border: 0" @click="choosePublishType">发布商品</el-button>
          <el-button type="primary"
           @click="$router.push('/demandPublish/index')" >发布需求</el-button
          >
        </div>
      </div>
    </div>
    <div class="tab-list">
      <div class="select">
        <el-select v-model="searchType2" :popper-append-to-body="false">
          <el-option
            v-for="(item, index) in productTypeList"
            :key="item.value"
            :value="item.value"
            :label="item.label"
          ></el-option>
        </el-select>
      </div>
      <div
        class="tab"
        v-for="(item, index) in tabList"
        :class="{ active: currentTab === index }"
        :key="index"
        @click="toggleTab(index)"
      >
        {{ item.name }}
      </div>
    </div>
    <div class="line"></div>
    <div style="background-color: #F7F7F7;width:100%;">
      <Breadcrumb></Breadcrumb>
    </div>
  </div>
</template>

<script>
import Breadcrumb from "@/components/Breadcrumb.vue";
export default {
  name: "PageHeader",
  components: {
    Breadcrumb,
  },
  data() {
    return {
      searchType: 1, // 1厂商  2二手 3租赁 4需求
      searchType2: 0, // 0全部 1设备 2建材
      keywords: '', // 关键字
      searchTypeList: [
        { label: "厂商", value: 1 },
        { label: "二手", value: 2 },
        { label: "租赁", value: 3 },
        { label: "需求", value: 4 },
      ],
      tabList: [
        { name: "首页", path: "/index" },
        { name: "厂家货源", path: "/productList/factory" },
        { name: "二手货源", path: "/productList/used" },
        { name: "租赁货源", path: "/productList/rentOut" },
        { name: "需求大厅", path: "/demandHall" },
      ],
      productTypeList: [
        { label: "全部产品", value: 0 },
        { label: "设备", value: 1 },
        { label: "建材", value: 2 },
      ],
      currentTab: 0,
    };
  },
  watch: {
    $route: {
      immediate: true,
      handler(val){
       let index = this.tabList.findIndex(item => item.path === val.fullPath) 
       if(index > -1){
        this.currentTab = index
       }
      }
    },
  },
  methods: {
    toggleTab(index, query = null) {
      this.currentTab = index;
      this.$router.replace({path: this.tabList[index].path, query});
    },
    choosePublishType(){
      this.$router.push('/publishType')
    },
    searchConfirm(){
      this.toggleTab(this.searchType, {keywords: this.keywords});
    }
  },
};
</script>

<style lang="scss" scoped>
.header-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  width: 100%;
  background: #fff;

  .header-box {
    width: 1200px;
    padding: 40px 0;

    .search-wrapper {
      height: 55px;

      .left {
        .logo {
          width: 66px;
          height: 66px;
          border-radius: 50%;
          margin-right: 20px;
        }
        .name {
          font-weight: 800;
          font-size: 30px;
          color: #333333;
        }
      }

      .center {
        height: 100%;
        position: relative;
        margin: 0 50px;
        width: 647px;
        background: #ffffff;
        border-radius: 0px;
        border: 2px solid #fe5a13;
        // height: 0.5625rem;

        .search-input {
          flex: 1;
          border: 0;
          outline: none;
          border-left: 1px solid #ccc;
          padding: 0 20px;
          height: 35px;
        }

        input{
          font-size: 18px;
        }

        ::v-deep .el-input__inner{
          font-size: 18px;
        }

        ::v-deep .el-select-dropdown__item{
          font-size: 18px;
        }
      }


      .search-btn {
        width: 59px;
        height: 100%;
        background: #fe5a13;
        cursor: pointer;

        .icon-search {
          width: 26px;
          height: 26px;
        }
      }
    }
  }

  .tab-list {
    display: flex;
    width: 1200px;

    .tab {
      display: flex;
      justify-content: center;
      align-items: center;
      flex: 1;
      padding: 17px 0;
      font-weight: 400;
      font-size: 18px;
      color: #333333;
      cursor: pointer;
    }

    .active {
      font-weight: bold;
      color: #fe5a13;
    }

    .select {
      display: flex;
      align-items: center;
      flex: 1;
      background: #fe5a13;

      ::v-deep .el-input__inner {
        background-color: #fe5a13;
        width: 100%;
        font-weight: bold;
        font-size: 18px;
        color: #ffffff;
      }
      ::v-deep .el-select__caret {
        color: #fff;
      }

      ::v-deep .el-select-dropdown__item{
          font-size: 18px;
        }
    }
  }

  .line {
    width: 100%;
    height: 2px;
    background: #fe5a13;
  }
}

::v-deep .el-input__inner {
  border: 0;
  width: 104px;
}

::v-deep .el-select {
  position: relative;
}

// 下拉框选中修改文字颜色
::v-deep .selected {
  color: #fe5a13 !important;
}
</style>
